package com.wxm.zst.zangshantang.controller;

import com.wxm.zst.zangshantang.model.EbNews;
import com.wxm.zst.zangshantang.model.EbProductCategory;
import com.wxm.zst.zangshantang.service.EbNewsService;
import com.wxm.zst.zangshantang.service.EbProductCategorySercie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private EbNewsService ebNewsService;

    @Autowired
    EbProductCategorySercie ebProductCategorySercie;

    @RequestMapping("/detail")
    public String detail(Model model, Integer enId){
        //1.调用service查询该新闻的详细信息
        EbNews ebNewsDetail = ebNewsService.detail(enId);
        //1.1.调用service层查询商品分类信息
        Map<String, List<EbProductCategory>> categoryMap = ebProductCategorySercie.selectBigAndSmallCate();
        //2.把数据绑定到model
        model.addAttribute("detail",ebNewsDetail);
        //2.1 将商品分类进行绑定
        model.addAttribute("categoryMap",categoryMap);
        //3.返回视图名称

        return "news-view";
    }

}
